<?php
$where='';
if(!empty($_GET['id'])){
	$id=$_GET['id'];//获取当前id
	$delid=cate($id);//获取当前项只下的所有子集的id
	$delid[]=$id;//加进去

	foreach ($delid as $key => $value) {
		$where.='id='.$value.' or ';
	}
	$where=substr($where,0,-4);
}else if(!empty($_POST)){//print_r($_POST);exit;
	foreach ($_POST['id'] as $key => $value) {
		$delid=cate($value);//获取当前项只下的所有子集的id
		$delid[]=$value;//加进去
			foreach ($delid as $key => $value) {
				$where.='id='.$value.' or ';
			}

	}
	$where=substr($where,0,-4);
}

$row=delete('category',$where);
if($row>-1){
	echo '<script>alert ("删除成功");location="index.php?admin=1&c=category&a=list";</script>';
	};

function cate($pid=0,$category=array()){

	$arr1=getlist('category','pid='.$pid);

	foreach ($arr1 as $k => $val) {
		$pid=$val['id'];
		$category[]=$pid;
		$category=cate($pid,$category);
	}
	return $category;
}

?>